﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Controllers;
using SystemCenterSoa.BaseLibrary.Tools.TypeTools;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.ContractManager;
using SystemCenterSoa.PoModel;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.PoModel.SystemManager.MyModelPo;
using SystemCenterSoa.Service.SystemManager;

namespace SystemCenterSoa.ApiProject.Area.SystemManager
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ContractController : MyBaseController
    {

        private StructuralService _StructBll;
        private DictionariesService _dictionariesService;
        public ContractController(StructuralService StructBll, DictionariesService dictionariesService)
        {
            _StructBll = StructBll;
            _dictionariesService = dictionariesService;
        }

        [HttpGet]
        public ResultModel<List<Build_TypePo>> GetBuildTree()
        {
            try
            {
                var data = _StructBll.GetBuildTree();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<Build_TypePo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<DictionariesPo>> GetDictionariesKey(string typeKey)
        {
            try
            {
                var data = _dictionariesService.GetDictionariesKey(typeKey);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DictionariesPo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<DictionariesPo>> GetDictionaryByType_key()
        {
            try
            {
                var data = _StructBll.GetDictionaryByType_key();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DictionariesPo>>(ex);
            }
        }


        [HttpGet]
        public ResultModel<List<Structural_style>> GetStructuralTree()
        {
            try
            {
                var data = _StructBll.StructuralTree();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<Structural_style>>(ex);
            }
        }


        [HttpPost]

        public ResultModel<bool> ContractAdd(ContractDto p)
        {
            ContractPo dbmodel = ModelCopier.CreateInstanceFrom<ContractPo>(p);
            dbmodel.create_time = DateTime.Now;
            dbmodel.create_name = LoginUser.user_name;
            try
            {
             
                var data = _StructBll.ContractAdd(dbmodel);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }
    }
}
